layui.config({
	base : "js/"
}).use(['form','layer','jquery','laypage'],function(){
	var $=layui.jquery,form=layui.form;
	//全选
	form.on('checkbox(allChoose)', function(data){
		var child = $(data.elem).parents('table').find("tbody input[type=checkbox]");
		child.each(function(index, item){
		  item.checked = data.elem.checked;
		});
		form.render('checkbox');
	});
	
	
	
	//查询所有
	inventoryinfoselectAll();
	//下一页
	$(".ClassXia").click(function(){
		if(pageCount>curPage){
			//清除
			$(".inventoryinfoTable tr:gt(0)").remove();
			curPage++;
			$(".dqy").text(curPage);
			inventoryinfoselectAll();
		}
		else if(pageCount==curPage){
			layer.msg('亲，已经是最后了!', {icon: 7, time: 2000});
		}
		
	})
	//上一页
	$(".ClassShang").click(function(){
		if(curPage>1){
			//清除
			$(".inventoryinfoTable tr:gt(0)").remove();
			curPage--;
			$(".dqy").text(curPage);
			inventoryinfoselectAll();
		}
		else if(curPage==1){
			layer.msg('亲，已经是首页了!', {icon: 7, time: 2000});
		}
		
	})
	//首页
	$(".ClassShou").click(function(){
		//清除
		$(".inventoryinfoTable tr:gt(0)").remove();
		curPage=1;
		$(".dqy").text(curPage);
		inventoryinfoselectAll();
	})
	//尾页
	$(".ClassWei").click(function(){
		//清除
		$(".inventoryinfoTable tr:gt(0)").remove();
		curPage=pageCount;
		$(".dqy").text(curPage);
		inventoryinfoselectAll();
	})
	
	$(".classSSBut").click(function(){	
		curPage=1;
		//当前数
		$(".dqy").text(curPage);
		inventoryinfoselectAll();
		
	})
	
	//查询配件类型
	inventoryinfoselectpTITypeName();
	//添加文章
	//改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）
	$(window).one("resize",function(){
		$(".newsAdd_btn").click(function(){
			var index = layui.layer.open({
				title : "",
				type : 2,
				content : "addinventoryinfo.jsp",
				success : function(layero, index){
					setTimeout(function(){
						/*
						layui.layer.tips('点击此处返回库存列表', '.layui-layer-setwin .layui-layer-close', {
							tips: 3
						});
						*/
					},500)
				}
			})			
			layui.layer.full(index);
		})
		$(document).on("click",".newsUpdate_btn",function(){
			var id=$(this).attr("name");
			var index = layui.layer.open({
				title : "",
				type : 2,
				content : "updateinventoryinfo.jsp?itiid="+id,
				success : function(layero, index){
					setTimeout(function(){
						/*
						layui.layer.tips('点击此处返回库存列表', '.layui-layer-setwin .layui-layer-close', {
							tips: 3
						});
						*/
					},500)
				}
			})			
			layui.layer.full(index);
		})
	}).resize();
	
})
//查询库存
$('.SelectInventotyinfo').on('click',function () {
	//清除
	$(".inventoryinfoTable tr:gt(0)").remove();
	inventoryinfoselectAll();
})
	var curPage=1;//当前页码
	var getPageCount=0;//总条数
	var pageCount=0;//总页数
	//切换每页条数
	$(".tr").change(function(){
		//清除
		$(".inventoryinfoTable tr:gt(0)").remove();
		inventoryinfoselectAll();
	})
function  inventoryinfoselectAll(){
	var pageSize=$(".tr option:checked").val();//每页条数
	
	var itiname=$(".itiname").val();//模糊查询的值
	//查询总数
	$.ajax({
		type:"post",
		url:"../inventoryinfoAction!pageCount",
		async:false,
		data:{"itiname":itiname},
		dataType:"json",
		success:function(msg){
			getPageCount=msg;
		}
	});
	pageCount=getPageCount/pageSize;
	if(getPageCount%pageSize!=0){
		pageCount=Math.ceil(pageCount);
	}
	//总页数
	$(".zys").text(pageCount);
	//总条数
	$(".zts").text(getPageCount);
	//当前页
	$(".dqy").text(curPage);
	var page=$(".dqy").text();
	$.ajax({
		type:"post",
		url:"../inventoryinfoAction!findAll",
		data:{"page":page,"tr":pageSize,"itiname":itiname},
		dataType:"json",
		success:function(msg){
			for(var i=0;i<msg.length;i++){
				//在表中追加一行数据
				var tr="<tbody class='news_content'><tr>" +
						"<td><input name='checked' lay-skin='primary' lay-filter='choose' type='checkbox'><div class='layui-unselect layui-form-checkbox' lay-skin='primary'><i class='layui-icon'></i></div></td>" +
						"<td align='left'>"+msg[i].ptitypeName+"</td>" +
						"<td>"+msg[i].ctitype+"</td>" +
						"<td>"+msg[i].itiname+"</td>" +
						"<td>"+msg[i].itiprice+"</td>" +
						"<td>"+msg[i].itiselling+"</td>" +
						"<td><img width='50' height='50' src='images/"+msg[i].iTIPicture+"'></img></td>" +
						"<td>"+msg[i].iTIParameter+"</td>" +
						"<td>"+msg[i].iTIEffect+"</td>" +
						"<td>"+msg[i].iTICount+"</td>" +
						"<td><a class='layui-btn layui-btn-mini news_edit newsUpdate_btn' name='"+msg[i].itItiid+"' name1='"+msg[i].ptitypeName+"' name2='"+msg[i].itiname+"'><i class='iconfont icon-edit'></i> 修改</a>" +
							"<a class='layui-btn layui-btn-danger layui-btn-mini news_del delectInventoryinfo' data-id='1' name='"+msg[i].itItiid+"'><i class='layui-icon'></i> 删除</a>" +
						"</td>" +
						"</tr></tbody>";
				$(".inventoryinfoTable").append(tr);
			}
		}
		
	});
	//判断删除和切换页
	if(pageCount<curPage){
		//清除
		$(".inventoryinfoTable tr:gt(0)").remove();
		curPage=1;
		$(".dqy").text(curPage);
		inventoryinfoselectAll();
	}
}
	
	
	//删除
	$(document).on("click",".delectInventoryinfo",function(){
		
		var id=$(this).attr("name");
		if (confirm('系统提示，您确定要删除此数据吗?')) {
			if(true){
				$.ajax({
					url:'../inventoryinfoAction!delectInventoryinfo',
					async:false,
					dataType:'json',
					data:{"inventoryinfo.itiid":id},
					type:'post',
					success:function(msg){
						if(msg)
						{
							layer.msg('操作成功!', {icon: 6, time: 2000});
							
						}
						else{
							layer.msg("删除失败！");
						}
						//清除
						$(".inventoryinfoTable tr:gt(0)").remove();
						inventoryinfoselectAll();
					}
				})
			}
			else{
				
			}
			
		}
	})
	
	
	


//查询配件类型追加到Option
function  inventoryinfoselectpTITypeName(){
	
}
	